package com.hkemmm.shop.controller;

import com.hkemmm.shop.dao.Order_detailMapper;
import com.hkemmm.shop.entity.Comment;
import com.hkemmm.shop.service.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
public class CommentController {
    @Autowired
    private ICommentService commentService;
    @Autowired
    private Order_detailMapper orderDetailMapper;

    @ResponseBody
    @RequestMapping("/GetComment")
    public List<Comment> getComment(Integer goodsId) {
        List<Comment> list = commentService.getCommentByGoods(goodsId);

        return list;
    }

    @ResponseBody
    @RequestMapping("/addComment")
    public String insertComment(Comment comment, Integer id) {
        comment.setAddtime(new Date());
        comment.setIsdelete(0);

        orderDetailMapper.updateStatus(id, 3);
        int i = commentService.insertSelective(comment);

        if(i == 0){
            return "err";
        }

        return "ok";
    }
}
